package com.wang.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class RestFul {

    //原始风格
    //localhost8080://项目名/r1?a=1&b=2
    @RequestMapping("/r1")
    public String test1(int a, int b, Model model){

        int s=a+b;
        model.addAttribute("msg",s);

        return "restful01";
    }

    //RestFul风格
    //localhost8080://项目名/r2/1/5(1和5是a，b的值)
    @RequestMapping("/r2/{a}/{b}")
    public String test2(@PathVariable int a,@PathVariable int b, Model model){

        int s=a+b;
        model.addAttribute("msg",s);
        return "restful02";
    }

    //用RestFul风格以get方式请求  方式一
    @RequestMapping(value="/r3/{a}/{b}",method = RequestMethod.GET)
    public String test3(@PathVariable int a,@PathVariable int b,Model model){
        int s=a+b;
        model.addAttribute("msg",s);
        return "restful03";
    }

    //用RestFul风格以get方式请求  方式二
    @GetMapping("/r4/{a}/{b}")
    public String test4(@PathVariable int a,@PathVariable int b,Model model){
        int s=a+b;
        model.addAttribute("msg",s);
        return "restful03";
    }


    //用RestFul风格以post方式请求  方式一(我们需要一个表单restful.jsp)
    //localhost8080://项目名/r5(因为是post请求,所以a,b不需要我们在url上赋值)
    @RequestMapping(value = "/r5/{a}/{b}",method = RequestMethod.POST)
    public String test5(@PathVariable int a,@PathVariable int b,Model model){
        int s=a+b;
        model.addAttribute("msg",s);
        return "restful05";
    }

    //方式二就相当于get请求的方式二 (@PostMapping)

}
